package view_manage

import (
	"time"
	"vrcm/src/vrcm/app/admin/models/view"
	imDto "vrcm/src/vrcm/app/admin/service/dto/im"
	"vrcm/src/vrcm/common/dto"
	common "vrcm/src/vrcm/common/models"
)

type ViewLimitGetPageReq struct {
	dto.Pagination `search:"-"`
	ViewLimitOrder
}

type ViewLimitOrder struct {
	Id            string `form:"idOrder"  search:"type:order;column:id;table:view_limit"`
	BindId        string `form:"bindIdOrder"  search:"type:order;column:bind_id;table:view_limit"`
	ViewPage      string `form:"viewPageOrder"  search:"type:order;column:view_page;table:view_limit"`
	ViewCondition string `form:"viewConditionOrder"  search:"type:order;column:view_condition;table:view_limit"`
	Format        string `form:"formatOrder"  search:"type:order;column:format;table:view_limit"`
	Barrage       string `form:"barrageOrder"  search:"type:order;column:barrage;table:view_limit"`
	CreateTime    string `form:"createTimeOrder"  search:"type:order;column:create_time;table:view_limit"`
	IsDelete      string `form:"isDeleteOrder"  search:"type:order;column:is_delete;table:view_limit"`
}

func (m *ViewLimitGetPageReq) GetNeedSearch() interface{} {
	return *m
}

type ViewLimitInsertReq struct {
	Id            int         `json:"-" comment:""` //
	BindId        string      `json:"bind_id" comment:"" validate:"required"`
	ViewPage      int         `json:"view_page" comment:"1 未启用 2 启用" validate:"required,gt=0"`
	ViewCondition int         `json:"view_condition" comment:"观看条件 1 密码观看 2 公开访问 3 手机白名单 4 短信验证 5 观看码观看"`
	Format        int         `json:"format" comment:"格式 1 mp4"`
	Barrage       int         `json:"barrage" comment:"1 未开启 2 开启"`
	LimitInfos    []LimitInfo `json:"limit_infos" comment:"限制信息 密码 手机号 观看码等等"`
	WhiteUsers    []WhiteUser `json:"white_users" comment:"白名单"`
	Welcome       string      `json:"welcome" comment:"欢迎语" validate:"required"`
	common.ControlBy
}

type WhiteUser struct {
	Id           int    `json:"id" comment:""` //
	UserId       string `json:"user_id" comment:"用户id"`
	UserName     string `json:"user_name" comment:"用户名"`
	PhoneOrEmail string `json:"phone_or_email" comment:"手机或者邮箱哈"`
}

func (s *ViewLimitInsertReq) Generate(model *view.ViewLimit) {
	if s.Id == 0 {
		model.Model = common.Model{Id: s.Id}
	}
	model.BindId = s.BindId
	model.ViewPage = s.ViewPage
	model.ViewCondition = s.ViewCondition
	model.Format = s.Format
	model.Barrage = s.Barrage
	model.CreateTime = time.Now().Unix()
	model.IsDelete = 2
	model.CreateBy = s.CreateBy
	model.UpdateTime = time.Now().Unix()
	model.Welcome = s.Welcome
}

func (s *ViewLimitInsertReq) GetId() interface{} {
	return s.Id
}

type ViewLimitUpdateReq struct {
	Id             int                  `uri:"id" comment:""` //
	TenantId       string               `json:"tenant_id" comment:"租户"`
	BindId         string               `json:"bind_id" comment:"" validate:"required,max=50"`
	ViewPage       int                  `json:"view_page" comment:"1 未启用 2 启用" validate:"required,gt=0"`
	ViewCondition  int                  `json:"view_condition" comment:"观看条件 1 密码观看 2 白名单" validate:"required,gt=0"`
	Format         int                  `json:"format" comment:"格式 1 mp4" validate:"required,gt=0"`
	Barrage        int                  `json:"barrage" comment:"1 开启 2 开启" validate:"required"`
	LimitInfos     []LimitInfo          `json:"limit_infos" comment:"限制信息 密码 手机号 观看码等等"`
	IMCreateReqDto imDto.IMCreateReqDto `json:"im_create_req_dto" comment:"创建im请求"`
	Welcome        string               `json:"welcome" comment:"欢迎语" validate:"required"`
	WeChatType     int                  `json:"wechat_type" comment:"1企业 2普通"`
	WhiteUsers     []WhiteUser          `json:"white_users" comment:"白名单"`
	common.ControlBy
}

type IMCreateReq struct {
	Name            string `json:"name" comment:"群名"`
	TenantId        string `json:"tenant_id" comment:"租户id"`
	GroupId         string `json:"group_id" comment:"群组id" `
	RoomType        string `json:"room_type" comment:"群组id"`
	Notification    string `json:"notification" comment:"群公告"`
	ApplyJoinOption string `json:"apply_join_option" comment:"申请加群处理方式。包含 FreeAccess（自由加入），NeedPermission（需要验证），DisableApply（禁止加群），不填默认为 NeedPermission（需要验证） 仅当创建支持申请加群的群组时，该字段有效"`
}

type LimitInfo struct {
	Id        int    `uri:"id" comment:""` //
	LimitInfo string `json:"limit_info" comment:"限制信息 密码 手机号 观看码等等"`
	UserName  string `json:"user_name" comment:"用户名或者昵称"`
	Account   string `json:"account" comment:"绑定账户"`
	Desc      string `json:"desc" comment:"描述"`
	IsSms     int    `json:"is_sms" comment:"是否短信验证 1 是 2否"`
	common.ModelTime
	common.ControlBy
}

func (s *ViewLimitUpdateReq) Generate(model *view.ViewLimit) {
	if s.Id == 0 {
		model.Model = common.Model{Id: s.Id}
		model.CreateBy = s.CreateBy
		model.CreateTime = time.Now().Unix()
		model.UpdateTime = time.Now().Unix()
	} else {
		model.Id = s.Id
		model.UpdateBy = s.UpdateBy
		model.UpdateTime = time.Now().Unix()
	}
	//微信
	if s.ViewCondition == 6 {
		model.WeChatType = s.WeChatType
	}
	model.BindId = s.BindId
	model.ViewPage = s.ViewPage
	model.ViewCondition = s.ViewCondition
	model.Format = s.Format
	model.Barrage = s.Barrage
	model.Welcome = s.Welcome
	model.IsDelete = 2
}

func (s *ViewLimitUpdateReq) GetId() interface{} {
	return s.Id
}

func (s *ViewLimitUpdateReq) GetBindId() interface{} {
	return s.BindId
}

// ViewLimitGetReq 功能获取请求参数
type ViewLimitGetReq struct {
	Id     int    `uri:"id"`
	BindId string `json:"bind_id" comment:"" validate:"required"`
}

type GetWhiteUserByLimitReq struct {
	LimitId int `json:"limit_id"`
}

// ViewLimitGetFilterReq 功能获取请求参数
type ViewLimitGetFilterReq struct {
	Id     int    `uri:"id"`
	BindId string `json:"bind_id" comment:"" validate:"required"`
	Type   int    `json:"type" comment:"" validate:"required" comment:"观看条件 1 密码观看 2 公开访问 3 手机白名单 4 短信验证 5 观看码观看" validate:"required,gt=0"`
}

func (s *ViewLimitGetReq) GetId() interface{} {
	return s.Id
}

// ViewLimitDeleteReq 功能删除请求参数
type ViewLimitDeleteReq struct {
	Ids []int `json:"ids"`
}

func (s *ViewLimitDeleteReq) GetId() interface{} {
	return s.Ids
}

type GenerateViewCodeReq struct {
	PaperNum int `json:"paper_num" comment:"生成张数" validate:"required"`
}

type SaveWhiteUserReq struct {
	Id         int         `json:"id" comment:""` //
	TenantId   string      `json:"tenant_id" comment:"租户"`
	LimitId    int         `json:"limit_id" comment:""`
	WhiteUsers []WhiteUser `json:"white_users" comment:"白名单"`
	common.ControlBy
}

type DeleteWhiteUserReq struct {
	Ids []int `json:"ids" comment:""` //
}

type GetWhiteUserReq struct {
	Id int `json:"id" comment:""` //
}

type CheckWhiteUserReq struct {
	LiveId   int    `json:"live_id" comment:""`
	LimitId  int    `json:"limit_id" comment:""`
	UserName string `json:"user_name" comment:"用户名"`
}
